package com.zj.juc.study.lockSupport;

import java.util.concurrent.TimeUnit;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName ObjectWaitNotifyPositionReplaceDemo
 * @Description wait和notify执行顺序互换
 * @createTime 2024年12月26日 22:51
 */
public class ObjectWaitNotifyPositionReplaceDemo {
    public static void main(String[] args) {
        Object lock = new Object();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock){
                System.out.println(Thread.currentThread().getName()+"\t"+".....come in");
                try {
                    lock.wait();//交出锁，阻塞
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+".....被唤醒");
            }
        },"t1").start();


        new Thread(()->{
            synchronized (lock){
                lock.notify();
                System.out.println("发出通知");
            }
        },"t2").start();
    }
}
